﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DARE.Save.DataStructures
{
    public class CPhysicObjectData : ISaveData
    {

        public bool immovable;
        public bool allowFreezing;
        public APhysicObject.ECollisionType collisionType;
        public CObjectData physicObject;

        public void FillDataStructure(object phyObj)
        {
            APhysicObject pObject = phyObj as APhysicObject;
            immovable = pObject.Body.Immovable;
            allowFreezing = pObject.Body.AllowFreezing;
            collisionType = pObject.CollisionType;

            if (pObject is CPhysicBox)
            {
                CBoxData obj = new CBoxData();
                obj.size = (pObject as CPhysicBox).Dimensions;
                physicObject = obj;
            }
            else if (pObject is CPhysicCapsule)
            {
                CCapsuleData obj = new CCapsuleData();
                obj.length = (pObject as CPhysicCapsule).Length;
                obj.diameter = (pObject as CPhysicCapsule).Diameter;
                physicObject = obj;
            }
            else if (pObject is CPhysicCylinder)
            {
                CCylinderData obj = new CCylinderData();
                obj.length = (pObject as CPhysicCylinder).Length;
                obj.diameter = (pObject as CPhysicCylinder).Diameter;
                physicObject = obj;
            }
            else if (pObject is CPhysicMesh)
            {
                CTriangleData obj = new CTriangleData();
                obj.includeNonColl = (pObject as CPhysicMesh).IncludeNoncoll;
                physicObject = obj;
            }

            else if (pObject is CPhysicMeshApprox)
            {
                CApproxData obj = new CApproxData();
                physicObject = obj;
            }
            else if (pObject is CPhysicPlane)
            {
                CPlaneData obj = new CPlaneData();
                obj.size = (pObject as CPhysicPlane).Size;
                physicObject = obj;
            }
            else if (pObject is CPhysicSphere)
            {
                CSphereData obj = new CSphereData();
                obj.diameter = (pObject as CPhysicSphere).Diameter;
                physicObject = obj;
            }
        }

        public void FillFromDataStructure(out object physicObj, params object[] paramsData)
        {
            APhysicObject pObject = null;

            if (physicObject is CBoxData)
            {
                CPhysicBox obj = new CPhysicBox((physicObject as CBoxData).size);
                pObject = obj;
            }
            else if (physicObject is CCapsuleData)
            {
                CPhysicCapsule obj = new CPhysicCapsule((physicObject as CCapsuleData).length, (physicObject as CCapsuleData).diameter);
                pObject = obj;
            }
            else if (physicObject is CCylinderData)
            {
                CPhysicCylinder obj = new CPhysicCylinder((physicObject as CCylinderData).length, (physicObject as CCylinderData).diameter);
                pObject = obj;
            }
            else if (physicObject is CPlaneData)
            {
                CPhysicPlane obj = new CPhysicPlane((physicObject as CPlaneData).size);
                pObject = obj;
            }
            else if (physicObject is CSphereData)
            {
                CPhysicSphere obj = new CPhysicSphere((physicObject as CSphereData).diameter);
                pObject = obj;
            }
            if (pObject != null)
            {
                pObject.Body.Immovable = immovable;
                pObject.Body.AllowFreezing = allowFreezing;
                pObject.CollisionType = collisionType;
            }

            physicObj = pObject;
        }
    }
}
